package com.lsh.oms.provider.service.order.frozen;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.dubbo.rpc.protocol.rest.support.ContentType;
import com.lsh.base.common.model.CommonResult;
import com.lsh.oms.api.model.order.OrderReturnDTO;
import com.lsh.oms.api.service.order.frozen.IOrderReturnFrozenRestService;
import com.lsh.oms.core.constant.ReturnCode;
import com.lsh.oms.core.service.order.frozen.OrderReturnFrozenService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

/**
 * Project Name: lsh-oms
 *
 * @author miaozhuang
 * @date 17/3/27
 * 北京链商电子商务有限公司
 * Package
 * desc:订单签收RestService
 */
@Service(protocol = "rest", timeout = 30000)
@Path("order/return")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({ContentType.APPLICATION_JSON_UTF_8})
@Deprecated
public class OrderReturnFrozenRestServiceImpl implements IOrderReturnFrozenRestService {

    private static Logger logger = LoggerFactory.getLogger(OrderReturnFrozenRestServiceImpl.class);

//    @Autowired
//    private OrderQueryService orderQueryService;

    @Autowired
    private OrderReturnFrozenService orderReturnFrozenService;

    @POST
    @Path("create")
    @Override
    public CommonResult<Object> create(OrderReturnDTO receiptDTO) {
//        String logSign = "logSign : " + ToolService.getLogSign();
//        long startTimeMs = System.currentTimeMillis();
//        logger.info(logSign + ": 黑狗更新订单状态（发货）入参 －－ " + (receiptDTO == null ? "" : JsonUtils.obj2Json(receiptDTO)));
        CommonResult<Object> commonResult = new CommonResult<>();
//        try {
//            if (receiptDTO == null) {
//                throw new BusinessException(ReturnCode.REQUEST_PARAMS_IS_NULL, "请求参数不合法，请检验。");
//            }
//            if (receiptDTO.getOrderCode() == null) {
//                throw new BusinessException(ReturnCode.REQUEST_PARAMS_IS_NULL, "请求参数不合法，请检验。");
//            }
//            OrderHead orderHead = orderQueryService.findByCode(receiptDTO.getOrderCode(), false, false);
//            if (orderHead == null) {
//                logger.info(logSign + "请求耗时:" + (startTimeMs - System.currentTimeMillis()) + "ms");
//                throw new BusinessException(ReturnCode.FIND_ORDER_IS_NULL, "用户订单号未查询到订单");
//            }
//            if (orderHead.getOrderStatus().compareTo(OrderStatus.ORDER_DELIVERY.getIndex()) < 0) {
//                throw new BusinessException(ReturnCode.ORDER_STATUS_ERROR, "订单状态是" + OrderStatus.getName(orderHead.getOrderStatus()) + "，请检验。");
//            }
//            orderHead.setUpdateTime(DateUtil.getCurrentTime());
//            commonResult = orderReturnFrozenService.createROOrder(orderHead, logSign);
//        } catch (BusinessException e) {
//            commonResult.setCode(e.getCode());
//            commonResult.setMessage(e.getMessage());
//            logger.error("业务异常code : " + e.getCode() + ",异常信息: " + e.getMessage(), e);
//        } catch (Exception e) {
//            commonResult.setCode(ExceptionStatus.E3001001.getCode());
//            commonResult.setMessage(ExceptionStatus.E3001001.getMessage());
//            logger.error("业务异常code : " + ExceptionStatus.E3001001.getCode() + ",异常信息: " + e.getMessage(), e);
//        }

        return commonResult;
    }


    @POST
    @Path("confirm")
    @Override
    public CommonResult<Integer> confirm(long code) {

        return new CommonResult<>(ReturnCode.REQUEST_SUCCESS, "ok", 1);
    }
}
